<?php
// +-------------------------------------------------------------------------------
// | DingZone [ A Rapid Development Framework For Dingtalk ]
// +-------------------------------------------------------------------------------
// | 组织架构相关Controller v1.0
// |
// | Copyright (c) 2014-2018 http://www.heimalanshi.com All rights reserved.
// | Author : Jie
// | Date : 2018-08-09
// +-------------------------------------------------------------------------------

namespace app\core\controller\enterprise\org;

use app\core\controller\enterprise\EnterpriseBaseController;
use app\core\model\EnterpriseDept;
use app\core\service\DingSyncService;

class IndexController extends EnterpriseBaseController {


    public function __construct() {
        parent::__construct();

        $this->_checkEnterpriseAdmin();
    }

    public function index() {
        $deptTree = EnterpriseDept::getTree($this->eid);
        $this->assign("deptTree", json_encode($deptTree));

        return view();
    }

    /**
     * 同步钉钉通讯录
     *
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function syncDing() {
        DingSyncService::syncDeptsAndUsers($this->enterprise);
        $this->success("同步成功");
    }
}
